<template>
  <div>
    <!-- 审核 -->
    <el-dialog
      v-el-drag-dialog
      title="充值审核"
      :visible.sync="visible"
      width="700px"
      @close="reset"
    >
      <el-form ref="dataForm" class="form" label-width="120px" label-position="right">
        <el-form-item label="客户编号">
          <el-input v-model="temp.csmCode" disabled />
        </el-form-item>
        <el-form-item label="客户名称">
          <el-input v-model="temp.csmName" disabled />
        </el-form-item>
        <el-form-item label="充值绑定手机号">
          <el-input v-model="temp.csmPhone" disabled />
        </el-form-item>
        <el-form-item label="充值卡号">
          <el-input v-model="temp.cardCode" disabled />
        </el-form-item>
        <el-form-item label="充值金额">
          <el-input v-model="feeCount1" disabled />
        </el-form-item>
        <el-form-item label="赠送金额">
          <el-input v-model="feeCount2" disabled />
        </el-form-item>
        <el-form-item label="卡内余额">
          <el-input v-model="moneyChange" disabled />
        </el-form-item>
        <el-form-item label-width="100px" label="备  注" style="width: 100%;">
          <el-input v-model="temp.accCsmcardRecordList[0].remark" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="pass(2)">通过</el-button>
        <el-button type="primary" @click="pass(3)">驳回</el-button>
        <el-button @click="reset">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { topUpAdministrationAudit } from '@/api'

  export default {
    name: 'deposit-audit',
    data() {
      return {
        visible: false,
        temp: {
          cardSurplus: '',
          accCsmcardRecordList: [
            { remark: '', feeCount1: '', feeCount2: '' }
          ]
        },
        recordId: ''
      }
    },
    computed: {
      // 金额
      moneyChange: function() {
        var val = this.temp.cardSurplus * 1.00 / 100
        val = Number(val)
        val = isNaN(val) ? '0.00' : val.toFixed(2)
        return val
      },
      feeCount1() {
        var val = this.temp.accCsmcardRecordList[0].feeCount1 * 1.00 / 100
        val = Number(val)
        val = isNaN(val) ? '0.00' : val.toFixed(2)
        return val
      },
      feeCount2() {
        var val = this.temp.accCsmcardRecordList[0].feeCount2 * 1.00 / 100
        val = Number(val)
        val = isNaN(val) ? '0.00' : val.toFixed(2)
        return val
      }
    },
    async created() {},
    methods: {
      async open(temp, recordId) {
        this.recordId = recordId
        this.temp = temp
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
        })
      },
      // 通过/驳回
      async pass(reviewType) {
        if (reviewType === 3 && this.temp.accCsmcardRecordList[0].remark === '') {
          this.$message({
            type: 'warning',
            message: '驳回必须添加备注信息!'
          })
          return
        }
        const { status } = await topUpAdministrationAudit({
          recordId: this.recordId,
          reviewType: reviewType,
          remark: this.temp.accCsmcardRecordList[0].remark
        })
        if (status === 200) {
          this.$message({
            type: 'success',
            message: `${reviewType === 2 ? '审核通过！' : '驳回成功！'}`
          })
          this.$emit('upDataCheckTable')
          this.visible = false
        }
      },
      // 关闭
      reset() {
        this.visible = false
      }
    }
  }
</script>

<style lang="scss" scoped>
.form {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
}
</style>
